#!/bin/bash
one=1
two=2
#let 不需要加$
let result=one+two
echo "3 $result"

let result=$one+3
echo "4 $result"

let result++
echo "5 $result"

let result--
echo "4 $result"

let result+=one
echo "5 $result"

#[] 可以加$也可以不加
result=$[ one+two ]
echo "3 $result"

result=$[ $one+4]
echo "5 $result"

#() 可以加$也可以不加
result=$((one+two))
echo "3 $result"

result=$(($one+$two))
echo "3 $result"

#expr 必须加$
result=`expr $one + $two`
echo "3 $result"

result=$(expr $one + $two)
echo "3 $result"

#bc 进行丰富的运算

echo "4 * 0.56" | bc

no=45
result="$no/2.5" | bc
echo "$result"

# 精度控制,小数点后2位
echo "scale=2;4*0.46" | bc

#进制控制,ibase要写在obase之后
no=10
echo "obase=2;$no" | bc

no=10110100
echo "obase=10;ibase=2;$no" | bc

# 平方与平方根
echo "sqrt(100)" | bc

echo "10^10" | bc
